package com.easytopit.demo.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

import com.easytopit.demo.domain.User;

public interface UserMapper {
	
	@Select({"select name from user where name = #{name,jdbcType=VARCHAR}"})
	String check(@Param("name")String name);
	
	@Insert({"insert into user (name,passwd)",
		"values (#{name,jdbcType=VARCHAR},#{passwd,jdbcType=VARCHAR})"})
	void reg(@Param("name")String name,@Param("passwd")String passwd);
	
	@Select({"select passwd from user where name = #{name,jdbcType=VARCHAR}"})
	@Results({
        @Result(column="passwd", property="passwd", jdbcType=JdbcType.VARCHAR)
    })
	String login(@Param("name")String name);
	
	@Select({
        "select name,passwd,face from user",
        "where name = #{name,jdbcType=VARCHAR} and passwd = #{passwd,jdbcType=VARCHAR}"
    })
	@Results({
		@Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="passwd", property="passwd", jdbcType=JdbcType.VARCHAR),
        @Result(column="face", property="face", jdbcType=JdbcType.VARCHAR)
    })
	User user(@Param("name")String name,@Param("passwd")String passwd);
	
	@Update({"update user set passwd = (#{passwd,jdbcType=VARCHAR}) where name = #{name,jdbcType=VARCHAR}"})
	void updatePasswd(@Param("name")String name,@Param("passwd")String passwd);
	
	@Update({"update user set face = (#{face,jdbcType=VARCHAR}) where name = #{name,jdbcType=VARCHAR}"})
	void setFace(@Param("face")String face,@Param("name")String name);
	
	@Update({"update user set email = (#{email,jdbcType=VARCHAR}) where name = #{name,jdbcType=VARCHAR}"})
	void setEmail(@Param("email")String email,@Param("name")String name);
}